﻿using Butcher.winform.Dto;
using Newtonsoft.Json.Linq;
using slaughters.Dto;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Traceability.Commont.DBContexts;
using Traceability.Commont.Domains;
using Traceability.Commont.DTOs.UsersFile;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Text.Json;
using System.Security.Permissions;

namespace Butcher.winform.EnterpriseForms.RBAC
{
    public partial class permissionList : Form
    {
        //private WebBrowser webBrowser = new();
        public permissionList()
        {
            InitializeComponent();
            //webBrowser.Dock = DockStyle.Fill;
            //this.Controls.Add(webBrowser);
        }

        public class Permissiones
        {
            public string? PermissionsName { get; set; } = null;
        }

        Permissiones permission = new Permissiones();
        private void permissionList_Load(object sender, EventArgs e)
        {
            Permissions str = new Permissions();
            permission.PermissionsName = str.PermissionsName;
            string url = @"http://localhost:5021/api/Trace/GetPermissions?info="+ str.PermissionsName;
            HttpClient client = new HttpClient();
            
            string result = client.GetStringAsync(url).Result;
            JObject info = JObject.Parse(result);
            var aaa = info["date"].Value<JArray>();
            List<Permissions> cts = aaa.ToObject<List<Permissions>>();

            foreach (var ct in cts)
            {
                dataGridView1.DataSource = cts;
            }

        }

        private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
        //    if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
        //    {
        //        Point curPosition = e.Location;//当前鼠标在当前单元格中的坐标
        //        if (this.dataGridView1.Columns[e.ColumnIndex].HeaderText == "操作")
        //        {
        //            Graphics g = this.dataGridView1.CreateGraphics();
        //            System.Drawing.Font myFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
        //            SizeF sizeDel = g.MeasureString("删除", myFont);
        //            SizeF sizeMod = g.MeasureString("修改", myFont);

        //        }
        //    }
        }

        //private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        //{
        //    Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, this.dataGridView1.RowHeadersWidth - 4, e.RowBounds.Height);
        //    TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), this.dataGridView1.RowHeadersDefaultCellStyle.Font, rectangle, this.dataGridView1.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.Right | TextFormatFlags.HorizontalCenter);
        //}

        //private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        //{
        //    if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
        //    {
        //        if (this.dataGridView1.Columns[e.ColumnIndex].HeaderText == "操作")
        //        {
        //            StringFormat sf = StringFormat.GenericDefault.Clone() as StringFormat;//设置重绘入单元格的字体样式
        //            sf.FormatFlags = StringFormatFlags.DisplayFormatControl;
        //            sf.Alignment = StringAlignment.Center;
        //            sf.LineAlignment = StringAlignment.Center;
        //            sf.Trimming = StringTrimming.EllipsisCharacter;

        //            //重绘边框

        //            //设置要写入字体的大小
        //            System.Drawing.Font myFont = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
        //            SizeF sizeDel = e.Graphics.MeasureString("删除", myFont);
        //            SizeF sizeMod = e.Graphics.MeasureString("修改", myFont);

        //            float fDel = sizeDel.Width / (sizeDel.Width + sizeMod.Width); //
        //            float fMod = sizeMod.Width / (sizeDel.Width + sizeMod.Width);

        //            //设置每个“按钮的边界”
        //            RectangleF rectDel = new RectangleF(e.CellBounds.Left, e.CellBounds.Top, e.CellBounds.Width * fDel, e.CellBounds.Height);
        //            RectangleF rectMod = new RectangleF(rectDel.Right, e.CellBounds.Top, e.CellBounds.Width * fMod, e.CellBounds.Height);
        //            e.Graphics.DrawString("删除", myFont, Brushes.Black, rectDel, sf); //绘制“按钮”
        //            e.Graphics.DrawString("修改", myFont, Brushes.Black, rectMod, sf);
        //            e.Handled = true;
        //        }
        //    }
        //}

       
    }
}
